//
//  Bundle+Namespace.swift
//  反射机制
//
//  Created by FunctionMaker on 2017/7/23.
//  Copyright © 2017年 FunctionMaker. All rights reserved.
//

import UIKit

extension Bundle {
    //计算型属性类似于函数，它本身不存储值，只参与计算
    var namespace: String {
        return infoDictionary?["CFBundleName"] as? String ?? ""
    }
    
    var appInfo: [[String: Any]]? {
        guard let path = Bundle.main.path(forResource: "main.json", ofType: nil),
              let data = NSData(contentsOfFile: path),
        let appInfo = try? JSONSerialization.jsonObject(with: data as Data, options: []) as? [[String: Any]]
        else {
            return nil
        }
        
        return appInfo
    }
    
    var appVersion: String {
        return infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
    }
    
    var emoticonsBundle: Bundle {
        guard let bundlePath = Bundle.main.path(forResource: "HMEmoticon.bundle", ofType: nil),
            let emoticonBundle = Bundle(path: bundlePath)

        else {
            return Bundle()
        }
        
        return emoticonBundle
    }
    
}
